package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.HomeClassBeen;
import cn.xfdzx.android.apps.shop.bean.HomeMarketInitDataBeen;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：市场banner下五个图片
 */
public class MarketClassGVAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<HomeMarketInitDataBeen.IndexWholesaleCategoryBean> mList=new ArrayList<>();
    private ImageView ivHomeClass;
    private TextView tvHomeClass;

    public MarketClassGVAdapter(Context mContext){
        this.mContext=mContext;

    }

    public void setData(ArrayList<HomeMarketInitDataBeen.IndexWholesaleCategoryBean> mList){
        this.mList=mList;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        view=View.inflate(mContext, R.layout.item_home_class,null);
        ivHomeClass= view.findViewById(R.id.iv_home_class);
        tvHomeClass=view.findViewById(R.id.tv_home_class);
        RequestOptions options=new RequestOptions();
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback( R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);
        Glide.with(mContext).load(mList.get(position).getPic()).apply(options).into(ivHomeClass);
        tvHomeClass.setText(mList.get(position).getName());
        return view;
    }
}
